package lib.self.ex.decor;

import android.content.Context;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import lib.self.R;

/**
 * description: loading view (dialog专用)
 * author: Steven Xiao
 * date: 2017/5/5
 */
public class DecorProgressView extends AppCompatImageView implements IDecorProgressView {
    private Animation mAnimRotate;

    public DecorProgressView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        setScaleType(ScaleType.CENTER_INSIDE);
        mAnimRotate = getLoadingAnim();
        mAnimRotate.setDuration(getLoadingDuration());
    }

    @Override
    public void start() {
        startAnimation(mAnimRotate);
    }

    @Override
    public void stop() {
        clearAnimation();
    }

    protected Animation getLoadingAnim() {
        return AnimationUtils.loadAnimation(getContext(), R.anim.rotate_infinite);
    }

    protected long getLoadingDuration() {
        return 500;
    }
}
